﻿using Raffles.OA.Data;
using Raffles.OA.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;

namespace Raffles.OA.WebApp.Areas.Manage.Controllers
{
    /// <summary>
    /// 日 期：2024-05-28 11:03:44
    /// 描 述：任务调度日志控制器类
    /// </summary>
    public class AutoJobLogController : BaseController<AutoJobLog>
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public ActionResult GetPageListJson(BaseSearchParam param, Pagination pagination)
        {
            int totalCount = 0;
            var datas = _dbContext.Queryable<AutoJobLog>()
                                .WhereIF(!param.KeyWord.IsEmpty(), x => x.JobGroupName.Contains(param.KeyWord.Trim()) || x.JobName.Contains(param.KeyWord.Trim()))
                                .ToPageList(pagination.PageIndex, pagination.PageSize, ref totalCount);
            return Content(DataResult<List<AutoJobLog>>.PageResult(datas, totalCount).ToJson());
        }

        /// <summary>
        /// 清空设置
        /// </summary> 
        /// <returns></returns>
        [HttpPost]
        public ActionResult LogClean()
        {
            try
            {
                _dbContext.Deleteable<AutoJob>().ExecuteCommand();
                return Json(DataResult.Success("清空成功"));
            }
            catch (Exception ex)
            {
                return Json(DataResult.Error($"清空失败,失败原因:{ex.Message}"));
            }
        }
    } 
}